package com.spark.core.transformation

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * intersection 取两个RDD的交集，两个RDD的类型要一致
 * 结果RDD的分区数与父rdd多的一致
 */
object Demo13_intersection {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("intersection")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val rdd1 = sc.parallelize(List[String]("zhangsan", "lisi", "wangwu"), 5)
    val rdd2 = sc.parallelize(List[String]("zhangsan", "lisi", "maliu"), 4)
    val intersectionRDD: RDD[String] = rdd1.intersection(rdd2)
    println("intersectionRDD partition length = " + intersectionRDD.getNumPartitions)

    intersectionRDD.foreach(println)
    sc.stop()
  }
}
